<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.google.gson.Gson"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script src="./js/jquery-1.9.1.js"></script>
<script src="./ibsheet/ibsheetinfo.js"></script>
<script src="./ibsheet/ibsheet.js"></script>
<script>
	$(document).ready(function() {
		//sheet 초기화  
		createIBSheet2(document.getElementById("viewArea"),"mySheet","100%","400px");
		
		var cfg = {SearchMode:smLazyLoad,Page:30};
		var headers = [
			{Text:"모델번호|평형|단가(A)|판매가(B)\nA * 1.03 / 100|현금구입가(C)\n A * 0.9 / 100|할부구입가(D)\nA * 0.93 / 100|현금부담액\nB-C|할부부담액\nB-D", Align:"Center"}
		];
		var info = {Sort:1,ColMove:1,ColResize:1,HeaderCheck:0};
		var cols = [
			{Type:"Text",Width:130},
			{Type:"Text",Width:100,ColMerge:0},
			{Type:"Int",Width:80,SaveName:"A", Align:"Right",ColMerge:0},
			{Type:"AutoSum",Width:85,SaveName:"B",Format:"#,##0.00",CalcLogic:"|A|*1.03/100", Align:"Right",ColMerge:0},
			{Type:"AutoSum",Width:85,SaveName:"C",Format:"#,##0.00",CalcLogic:"|A|*0.9/100", Align:"Right",ColMerge:0},
			{Type:"AutoSum",Width:85,SaveName:"D",Format:"#,##0.00",CalcLogic:"|A|*0.93/100", Align:"Right",ColMerge:0},
			{Type:"AutoAvg",Width:85,Format:"#,##0.00",CalcLogic:"|B|-|C|",ColMerge:1, Align:"Right",ColMerge:0},
			{Type:"AutoAvg",Width:85,Format:"#,##0.00",CalcLogic:"|B|-|D|", Align:"Right",ColMerge:0}
		];

		mySheet.SetConfig(cfg);
		mySheet.InitHeaders(headers,info);
		mySheet.InitColumns(cols);

		mySheet.FitColWidth();
		
		doAction("subsum");
	});
	
	/*Sheet 각종 처리*/
	function doAction(sAction) {
		
		switch(sAction) {
			case "search":		//조회
				mySheet.DoSearch("./data/sheet_data2.xml");
				break;
			case "subsum":
			    var info = [{StdCol:0, SumCols:"2|3|4|5", ShowCumulate:0,Sort:0,CaptionCol:0}];
			   	mySheet.ShowSubSum(info); 
			   	doAction('search');
			   	break;
			case "json":
				var rowJson = mySheet.GetRowJson(1);
				//var obj = $.parseJSON(rowJson);

				console.log(rowJson.A);
				<%
				Gson gson = new Gson();
				%>
				
				break;
				
			case "datacopy":
				var Row = mySheet.DataCopy();

				console.log(Row);
				break;
		    break;
		}
	}
	
</script>
<title>JSON 값 추출 예제</title>
</head>
<body>
<div id="main">
	<div id="title">JSON 값 추출 예제</div>
	<div><input type="button" value="JSON" onClick="doAction('json')"/></div>
	<div><input type="button" value="DATACOPY" onClick="doAction('datacopy')"/></div>
	<div id="viewArea"></div>
</div>
</body>
</html>
